from config.all_paths import config_variable_path
from config.global_variable import XCXSIP
from utils.file_handling.txt_handling import extract_txt


def XCXSIPDataProcessing(data, res):
    """
    小程序SIP通话数据处理
    """
    # 外呼
    if data.get('case_name') == '获取昨日小程序外呼总数量':
        total_all = str(res.json()['data']['total'])
        XCXSIP['outbound_call']['total_all'] = total_all
    elif data.get('case_name') == '获取昨日小程序外呼接通成功数量':
        Successfully_connected = str(res.json()['data']['total'])
        XCXSIP['outbound_call']['Successfully_connected'] = Successfully_connected
    elif data.get('case_name') == '获取昨日小程序外呼无人接听数量':
        no_answer = str(res.json()['data']['total'])
        XCXSIP['outbound_call']['no_answer'] = no_answer
    elif data.get('case_name') == '获取昨日小程序外呼中断呼叫数量':
        interrupt_call = str(res.json()['data']['total'])
        XCXSIP['outbound_call']['interrupt_call'] = interrupt_call
    elif data.get('case_name') == '获取昨日小程序外呼呼叫失败数量':
        call_failure = str(res.json()['data']['total'])
        XCXSIP['outbound_call']['call_failure'] = call_failure

    # 回拨
    elif data.get('case_name') == '获取昨日小程序回拨总数量':
        total_all = str(res.json()['data']['total'])
        XCXSIP['callback']['total_all'] = total_all
    elif data.get('case_name') == '获取昨日小程序回拨接通成功数量':
        Successfully_connected = str(res.json()['data']['total'])
        XCXSIP['callback']['Successfully_connected'] = Successfully_connected
    elif data.get('case_name') == '获取昨日小程序回拨无人接听数量':
        no_answer = str(res.json()['data']['total'])
        XCXSIP['callback']['no_answer'] = no_answer
    elif data.get('case_name') == '获取昨日小程序回拨中断呼叫数量':
        interrupt_call = str(res.json()['data']['total'])
        XCXSIP['callback']['interrupt_call'] = interrupt_call
    elif data.get('case_name') == '获取昨日小程序回拨呼叫失败数量':
        call_failure = str(res.json()['data']['total'])
        XCXSIP['callback']['call_failure'] = call_failure



    extract_txt(config_variable_path, str(XCXSIP))

